package com.jackstraw.jack_base.mq.common.entity.enums;

import java.util.concurrent.TimeUnit;

/**
 * 定时/延时 消息等级
 */
public enum DelayMessageLevelEnum {
    ONE_SECONDS(1, TimeUnit.SECONDS, 1, "1s"),
    FIVE_SECONDS(2, TimeUnit.SECONDS, 5, "5s"),
    TEN_SECONDS(3, TimeUnit.SECONDS, 10, "10s"),
    THIRTY_SECONDS(4, TimeUnit.SECONDS, 30, "30s"),
    ONE_MINUTES(5, TimeUnit.MINUTES, 1, "1m"),
    TWO_MINUTES(6, TimeUnit.MINUTES, 2, "2m"),
    THREE_MINUTES(7, TimeUnit.MINUTES, 3, "3m"),
    FOUR_MINUTES(8, TimeUnit.MINUTES, 4, "4m"),
    FIVE_MINUTES(9, TimeUnit.MINUTES, 5, "5m"),
    SIX_MINUTES(10, TimeUnit.MINUTES, 6, "6m"),
    SEVEN_MINUTES(111, TimeUnit.MINUTES, 7, "7m"),
    EIGHT_MINUTES(12, TimeUnit.MINUTES, 8, "8m"),
    NINE_MINUTES(13, TimeUnit.MINUTES, 9, "9m"),
    TEN_MINUTES(14, TimeUnit.MINUTES, 10, "10m"),
    twenty_MINUTES(15, TimeUnit.MINUTES, 20, "20m"),
    THIRTY_MINUTES(16, TimeUnit.MINUTES, 30, "30m"),
    ONE_HOURS(17, TimeUnit.HOURS, 1, "1"),
    TWO_HOURS(18, TimeUnit.HOURS, 2, "2"),
    ;

    /**
     * 等级
     */
    private Integer delayLevel;

    private TimeUnit timeUnit;

    private Integer timeUnitNum;
    /**
     * 等级所对应的时间
     */
    private String dateTime;

    DelayMessageLevelEnum(Integer delayLevel, TimeUnit timeUnit, Integer timeUnitNum, String dateTime) {
        this.delayLevel = delayLevel;
        this.timeUnit = timeUnit;
        this.timeUnitNum = timeUnitNum;
        this.dateTime = dateTime;
    }

    public Integer getDelayLevel() {
        return delayLevel;
    }

    public DelayMessageLevelEnum setDelayLevel(Integer delayLevel) {
        this.delayLevel = delayLevel;
        return this;
    }

    public String getDateTime() {
        return dateTime;
    }

    public DelayMessageLevelEnum setDateTime(String dateTime) {
        this.dateTime = dateTime;
        return this;
    }

    public TimeUnit getTimeUnit() {
        return timeUnit;
    }

    public DelayMessageLevelEnum setTimeUnit(TimeUnit timeUnit) {
        this.timeUnit = timeUnit;
        return this;
    }

    public Integer getTimeUnitNum() {
        return timeUnitNum;
    }

    public DelayMessageLevelEnum setTimeUnitNum(Integer timeUnitNum) {
        this.timeUnitNum = timeUnitNum;
        return this;
    }

    public static DelayMessageLevelEnum get(TimeUnit timeUnit, Integer timeUnitNum) {
        for (DelayMessageLevelEnum delayMessageLevelEnum : DelayMessageLevelEnum.values()) {
            if (delayMessageLevelEnum.getTimeUnit().equals(timeUnit)
                    && delayMessageLevelEnum.getTimeUnitNum().equals(timeUnitNum)) {
                return delayMessageLevelEnum;
            }
        }
        return null;
    }
}
